package com.dreamer.view;

import com.dreamer.domain.mall.transfer.Transfer;
import com.dreamer.domain.mall.transfer.TransferVo;
import com.dreamer.domain.user.User;
import com.dreamer.service.count.CountHandler;
import com.dreamer.service.mobile.TransferHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import ps.mx.otter.utils.WebUtil;
import ps.mx.otter.utils.message.Message;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class CountController {

    private final Logger LOG = LoggerFactory.getLogger(getClass());


    //计算补贴页面
    @RequestMapping("/count/voucher/calcuate.html")
    public String calcuateVoucher(){
        return "/count/voucher/calcuate";
    }

    /**
     * 计算补贴
     * @param response
     */
    @ResponseBody
    @RequestMapping("/count/voucher/calcuate.json")
    public void calcuateVoucher(String startTime,String endTime,HttpServletResponse response){
        countHandler.calculateFund(response,startTime,endTime);
    }

    @RequestMapping("/count/transfer/calcuate.json")
    @ResponseBody
    public List<Object> cacluateTransfer(HttpServletRequest request){
        User user = (User) WebUtil.getCurrentUser(request);
        if(user.isAdmin()){
            user.setId(3);
        }
        //找出我下面的人的进出货
        List<Object> transfers = transferHandler.cacluateTransfer(user.getId());
        return transfers;
    }

    @RequestMapping("/count/transfer/calcuate.html")
    public String toCacluateTransfer(){
            return "/count/transfer/calculate";
    }

    @Autowired
    private CountHandler countHandler;

    @Autowired
    private TransferHandler transferHandler;


}
